<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>学生详细信息</title>
</head>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
<body>
    <table align="center" width="80%" border="1px" bgcolor="#fff8dc">
        <tr>
            <th>学号</th>
            <th>姓名</th>
            <th>密码</th>
            <th>年龄</th>
            <th>生日</th>
            <th>家庭住址</th>
            <th>操作&nbsp;&nbsp;
                <a href="/student/toAdd">添加新学生</a>
                <a href="/user/logOut">退出登录</a>
            </th>
        </tr>
        <tr th:each="student : ${students}">
            <td th:text="${student.id}"></td>
            <td th:text="${student.studentName}"></td>
            <td th:text="${student.password}"></td>
            <td th:text="${student.age}"></td>
            <td th:text="${student.birthday}"></td>
            <td th:text="${student.address}"></td>
            <td>
                <a th:href="'/student/findById/'+${student.id}+''">修改</a>
                <button th:onclick="'del('+${student.id}+')'">删除</button>
            </td>
        </tr>
    </table>
</body>
<script>
    function del(id) {
        //JSON.stringify({id:id}),使用json.stringify将数据格式转换为json
        $.ajax({
            url:"/student/delete",
            data:JSON.stringify({id:id}),
            contentType:"application/json",
            success:function (res){
                if (res == "success"){
                    //刷新页面
                    window.location.href=window.location.href
                }
            }
        })

    }
</script>
</html>